import { mapActions, mapGetters } from 'vuex';
const jumpPageMixin = {
  computed: {
    ...mapGetters(['topMenus']),
  },
  methods: {
    ...mapActions(['handleLeftMenus']),
    /**
     * 页面跳转
     * @param topMenuName 跳转页面的顶部导航名称
     * @param path 跳转页面的路径
     */
    jumpPage(topMenuName, path, params = {}) {
      // 通过顶部导航名称查找到对应的menuCode，加载对应的左导航
      let findTopMenu = this.topMenus.find(item => item.menuName === topMenuName);
      if (findTopMenu) {
        let menuCode = findTopMenu.menuCode;
        this.handleLeftMenus(menuCode);
      }

      // 跳转页面
      this.$router.push({ path, query: params })
    }
  },
}

export { jumpPageMixin }